//
//  FullLoadingView.m
//  IBaby
//
//  Created by ZengYuan on 14/12/4.
//  Copyright (c) 2014年 com.zhongwei. All rights reserved.
//

#import "FullLoadingView.h"
#import "Config.h"

@implementation FullLoadingView

-(id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    self.backgroundColor=[UIColor whiteColor];
    
    float v = 640/283.0;
    
    //    UIImageView *imgview = [[UIImageView alloc]initWithFrame:CGRectMake(0, self.frame.size.height-self.frame.size.width/v,self.frame.size.width,self.frame.size.width/v)];
    //    imgview.image=[UIImage imageNamed:@"commonbknotitle"];
    //    [self addSubview:imgview];
    //    imgview.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
    
    self.btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:self.btn];
    [self.btn setFrame:self.bounds];
    
    return self;
}

-(void)dismissLoadingState{
    if (waitview) {
        [waitview stopRoll];
        [waitview removeFromSuperview];
        waitview = nil;
    }
}


-(void)showLoadingState{
    if (errorView) {
        [errorView removeFromSuperview];
        errorView = nil;
    }
    
    if (!waitview) {
        waitview = [[WaitView alloc]initWithFrame:CGRectMake(0, 0, 100, 63)];
        [self addSubview:waitview];
        CGPoint point = self.center;
        point.y=150;
        waitview.center = point;
        waitview.tipLabel.textColor=RGB(82, 82, 82);
        
        waitview.backgroundColor=[UIColor clearColor];
        waitview.autoresizingMask = UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
        [waitview startRoll];
    }
    
}


-(void)showErrorMsg:(NSString *)msg{
    
    
    if (waitview) {
        [waitview stopRoll];
        [waitview removeFromSuperview];
        waitview = nil;
    }
    
    if (!errorView) {
        
        
        errorView = [[ErrorView alloc]initWithFrame:CGRectMake(0, 0, 75, 29) text:msg];
        [self addSubview:errorView];
        errorView.backgroundColor=[UIColor clearColor];
        errorView.errLabel.textColor = RGB(82, 82, 82);
        
        if(msg.length>20){
            errorView.errLabel.numberOfLines=0;
            errorView.errLabel.font=[UIFont systemFontOfSize:14];
            CGRect rec = errorView.errLabel.frame;
            rec.origin.y=0;
            rec.size.width+=10;
            rec.size.height+=20;
            errorView.errLabel.frame=rec;
            
            rec = errorView.frame;
            rec.size.height+=20;
            rec.size.width+=10;
            errorView.frame=rec;
        }
        
        CGPoint point = self.center;
        point.y=150;
        errorView.center = point;
        
        errorView.backgroundColor=[UIColor clearColor];
        errorView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
        
        
    }else{
        errorView.errLabel.text=msg;
    }
}


-(void)dealloc{
    [waitview stopRoll];
    [waitview removeFromSuperview];
}

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

-(void)showUnAccessWarningView{
    UIImageView *imgview = [[UIImageView alloc]initWithFrame:CGRectMake((kScreenWidth-132)/2, 90, 132, 132)];
    imgview.image=[UIImage imageNamed:@"Privilege"];
    
    [self addSubview:imgview];
    
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, imgview.frame.size.height+imgview.frame.origin.y+30, kScreenWidth, 50)];
    label.text=@"请联系您的幼儿园\n为您开通账号";
    [self addSubview:label];
    label.font = [UIFont systemFontOfSize:18];
    label.textColor =RGB(255, 184, 86);
    label.textAlignment = NSTextAlignmentCenter;
    label.backgroundColor=[UIColor clearColor];
    label.numberOfLines=0;
    
    label = [[UILabel alloc]initWithFrame:CGRectMake(0, imgview.frame.size.height+imgview.frame.origin.y+80, kScreenWidth, 50)];
    label.text=@"即可享受本服务";
    [self addSubview:label];
    label.font = [UIFont systemFontOfSize:13];
    label.textColor = [UIColor lightGrayColor];
    label.backgroundColor=[UIColor clearColor];
    label.textAlignment = NSTextAlignmentCenter;
    
    label.numberOfLines=0;
    
    
}

@end
